package com.csust.travel.common;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Result {

    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";

    private String code;
    private String msg;
    private Object data;

    public Result() {}

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static class ResultBuilder {
        private String code;
        private String msg;
        private Object data;

        public ResultBuilder code(String code) {
            this.code = code;
            return this;
        }

        public ResultBuilder msg(String msg) {
            this.msg = msg;
            return this;
        }

        public ResultBuilder data(Object data) {
            this.data = data;
            return this;
        }

        public Result build() {
            return new Result(code, msg, data);
        }
    }

    public static Result success() {
        return new ResultBuilder().code(CODE_SUCCESS).msg("请求成功").build();
    }

    public static Result success(Object data) {
        return new Result(CODE_SUCCESS, "请求成功", data);
    }

    public static Result error(String msg) {
        return new Result(CODE_SYS_ERROR, msg, null);
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error() {
        return new Result(CODE_SYS_ERROR, "系统错误", null);
    }
}
